﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElevatorDispatching
{
    /// <summary>
    /// 表示一个按钮是否被按下的状态
    /// </summary>
    public class ButtonState : BindableBase
    {
        private bool _isPressed;

        public bool IsPressed
        {
            get => _isPressed;
            private set
            {
                if (SetProperty(ref _isPressed, value)) StateChangedTime = DateTimeOffset.Now;
            }
        }

        private DateTimeOffset _stateChangedTime;

        public DateTimeOffset StateChangedTime { get => _stateChangedTime; set => SetProperty(ref _stateChangedTime, value); }


        /// <summary>
        /// 初始化一个按钮的状态信息
        /// </summary>
        /// <param name="isPressed">指示按钮是否被按下</param>
        public ButtonState(bool isPressed)
        {
            IsPressed = isPressed;
            StateChangedTime = DateTimeOffset.Now;
        }

        /// <summary>
        /// 初始化一个未被按下的按钮
        /// </summary>
        public ButtonState() : this(false) { }

        /// <summary>
        /// 将按钮的状态转换为“按下”
        /// </summary>
        public void Press() => IsPressed = true;

        /// <summary>
        /// 将按钮状态转换为“未按下”
        /// </summary>
        public void Reset() => IsPressed = false;
    }
}
